﻿using System.Collections.Generic;
using System.Linq;
using Gumini.JulaDB.DataTypes;

namespace Gumini.JulaDB.Expressions.Functions
{
    /// <summary>
    /// Calculates length of a string.
    /// </summary>
    internal class LenFunction : ScalarFunction
    {
        public LenFunction()
            : base("len", 1) { }

        public override object Evaluate(IEnumerable<object> args)
        {
            string arg = (string)DataType.Varchar.ConvertFrom(args.Single());
            return (decimal)arg.Length;
        }

        public override DataType GetReturnType()
        {
            return DataType.Number;
        }
    }
}
